#include "gd32f30x.h"
#include "stdint.h"
#include "stdio.h"
#include "DevicesExti.h"


void vExtiKeyInit(void)
{
    /* enable the GPIO clock */
    rcu_periph_clock_enable(RCU_GPIOE);

    /* configure pin as input */
    gpio_init(EXTI_KEY_POWER_GPIO_Port, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, EXTI_KEY_POWER_Pin);


    /* enable and set key EXTI interrupt to the lowest priority */
    nvic_irq_enable(EXTI4_IRQn, 4U, 0U);

    /* connect key EXTI line to key GPIO pin */
    gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOE, GPIO_PIN_SOURCE_4);

    exti_interrupt_flag_clear(EXTI_4);

    /* configure key EXTI line */
    exti_init(EXTI_4,  EXTI_INTERRUPT, EXTI_TRIG_FALLING);
}
